package com.liangzhong.proxy.guide
{
	import com.liangzhong.commandconst.commandType.MainCommandType;
	import com.liangzhong.commandconst.guide.CMD_Guide;
	import com.liangzhong.errortip.ErrorTips;
	import com.liangzhong.global.CMD_Head;
	import com.liangzhong.proxy.BaseProxy;
	import com.socket.clientsocket.IClientSocket;
	
	import flash.utils.ByteArray;
	
	import lz.controls.Alert;

	/**
	 * Guide Proxy
	 * @author lake
	 * 
	 */	
	public class GuideProxy extends BaseProxy
	{
		public static const ProxyName :String = "GuideProxy";
		
		public function GuideProxy(proxyName:String = ProxyName, data:Object=null)
		{
			super(proxyName, data);
		}
		/**
		 * 数据读取
		 * @param mainCmdID
		 * @param subCmdID
		 * @param buffer
		 * @param dataSize
		 * @param clientSocket
		 * @return 
		 */		
		override public function onSocketRead(mainCmdID:uint,
											  subCmdID:uint,
											  buffer:ByteArray, 
											  dataSize:int, 
											  clientSocket:IClientSocket):Boolean
		{
			switch(mainCmdID)
			{
				case MainCommandType.TASK:
				{
					return onDeal(mainCmdID,subCmdID,buffer,dataSize);
				}
			}
			return false;
		}
		/**
		 * 处理信息
		 * @param mainCmdID
		 * @param subCmdID
		 * @param buffer
		 * @param dataSize
		 * @return 
		 * 
		 */		
		private function onDeal(mainCmdID:uint,
									subCmdID:uint,
									buffer:ByteArray, 
									dataSize:int):Boolean
		{
			
			switch(subCmdID)
			{
				case CMD_Guide.POST_GUIDE://提交引导
				{
					var retCode :int  = buffer.readInt();
					if(retCode != 0)
					{
						Alert.showErrorTip(ErrorTips.instance.getCErrorTip(retCode) + "");
					}
					return true;
				}
			}
			return false;
		}
		/**
		 *提交引导 
		 * @param param
		 * 
		 */		
		public function postGuide(param :*):void
		{
			var sendBuf :ByteArray = 
				CMD_Head.getHeadByteArrayBuff(CMD_Head.Size + 2,MainCommandType.TASK,CMD_Guide.POST_GUIDE);
			sendBuf.writeShort(int(param.step));
			sendBuf.position = 0;
			clientSocket.sendData(sendBuf,sendBuf.bytesAvailable);
		}
	}
}